package chatclient_01;

import java.awt.AWTException;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.TrayIcon;
import java.awt.TrayIcon.MessageType;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import network_01.ResourceManager;

public class TrayManager
{
  private SystemTray tray = SystemTray.getSystemTray();
  private TrayIcon trayIcon;

  public TrayManager(String iconPath, PopupMenu popup)
  {
    this.trayIcon = new TrayIcon(ResourceManager.createImage(getClass(), iconPath), "Chat Client");
    this.trayIcon.setPopupMenu(popup);
  }

  public void setImageAutoSize(boolean b) {
    this.trayIcon.setImageAutoSize(b);
  }

  public void addActionListener(ActionListener al) {
    this.trayIcon.addActionListener(al);
  }

  public void removeIcon() {
    this.tray.remove(this.trayIcon);
  }

  public void addIcon() {
    try {
      this.tray.add(this.trayIcon);
    } catch (AWTException ex) {
      Logger.getLogger(TrayManager.class.getName()).log(Level.SEVERE, null, ex);
    }
  }

  public void displayMessage(String caption, String text, TrayIcon.MessageType messageType) {
    this.trayIcon.displayMessage(null, null, TrayIcon.MessageType.ERROR);
  }
}